package com.zy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zy.entity.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderMapper extends BaseMapper<Order> {
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "pricing_standard_id",property = "pricingStandard",one=@One(select = "com.zy.mapper.PricingStandardMapper.selectById")),
            @Result(column = "parking_lot_id",property = "parkingLot",one=@One(select = "com.zy.mapper.ParkingLotMapper.getById")),
            @Result(column = "vehicle_id",property = "vehicle",one=@One(select = "com.zy.mapper.VehicleMapper.getById")),

    })
    @Select("SELECT *" +
            "FROM orders AS o, vehicle AS v, pricing_standard AS ps, parking_lot AS pl " +
            "WHERE o.vehicle_id = v.id " +
            "AND o.parking_lot_id = pl.id " +
            "AND o.pricing_standard_id = ps.id;")

    List<Order> getAll();
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "pricing_standard_id",property = "pricingStandard",one=@One(select = "com.zy.mapper.PricingStandardMapper.selectById")),
            @Result(column = "parking_lot_id",property = "parkingLot",one=@One(select = "com.zy.mapper.ParkingLotMapper.getById")),
            @Result(column = "vehicle_id",property = "vehicle",one=@One(select = "com.zy.mapper.VehicleMapper.getById")),

    })
    @Select("SELECT *" +
            "FROM orders AS o, vehicle AS v, pricing_standard AS ps, parking_lot AS pl " +
            "WHERE o.vehicle_id = v.id " +
            "AND o.parking_lot_id = pl.id " +
            "AND o.pricing_standard_id = ps.id " +
            "and o.id=#{id};")
    Order getById(Long id);
    @Insert("insert into orders set in_DateTime=#{inDateTime},out_DateTime=#{outDateTime},price=#{price}" +
            ",isPayComplete=#{isPayComplete},isRequireInvoicing=#{isRequireInvoicing}" +
            ",pricing_standard_id=#{pricingStandard.id},parking_lot_id=#{parkingLot.id},vehicle_id=#{vehicle.id}")
    int insert(Order entity);
    @Update("update orders set in_DateTime=#{inDateTime},out_DateTime=#{outDateTime},price=#{price} " +
            ",isPayComplete=#{isPayComplete},isRequireInvoicing=#{isRequireInvoicing} " +
            ",pricing_standard_id=#{pricingStandard.id},parking_lot_id=#{parkingLot.id},vehicle_id=#{vehicle.id}  " +
            "where id=#{id}")
    int update(Order entity);
}
